<template>
      <el-dialog title="客户编辑" :visible.sync="show" width="40%" 
      :before-close="dialogClose">
      <el-form ref="form" :model="item" label-width="80px">
          <el-form-item label="客户名称">
                <el-input v-model="item.name" class="select_input"></el-input>
          </el-form-item>
          <el-form-item label="客户分类">
              <el-select v-model="item.cid" placeholder="请选择产品分类">
                  <el-option v-for="(item,index) in cate" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="联系电话">
              <el-input v-model="item.phone" class="select_input"></el-input>
          </el-form-item>
          <el-form-item label="客户邮箱">
          <el-input v-model="item.email" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="客户地址">
           <el-input type="textarea" placeholder="请输入地址" v-model="item.address"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="add">确 定</el-button>
          <el-button @click="dialogClose">取 消</el-button>
        </el-form-item>



      </el-form>
    </el-dialog>
</template>
 
<script>
export default {
  name: "userEdit",
  props:['item','show','tags','cate'],
  data() {
    return {
      imgUrl:this.url,
      inputValue: '',
      inputVisible:false,
      apiUrl:this.apiUrl+'public/upload',
    };
  },
  created: function(e) {
      //this.getCate()
  },
  methods: {
    dialogClose:function(){
      this.$emit("func",{'key':'editShow','type':0})
    },
    add:function(){
      var that = this
      var validate = {
        name:'客户名称不能为空',
        cid:'请选择客户分类',
        phone:'客户电话不能为空'
      }

      for(var x in validate){
        if(!this.item[x]){
          this.$message.error(validate[x]);
          break;
          return;
        }
      }
      this.$post('user/add',this.item).then((res) => {
          if(res.code == 1){
            that.$message.success(res.msg);
            that.$emit("func",{'key':'editShow','type':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
};
</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>